import Axios from '@/util/ajax'

const state = {
    isInitialized: false,
    //保存报价所有页面都会用到的一些值 ：如下拉框的列表值等,
    initPageData: {
        customers: [], // 客户列表
        sells:[], // 销售人员
        statusList:[],
    },
    receiptList: [],
    receipt:{},
    showReceiptList: false,
    isView: false,
    showReceiptDialog: true,
    orderId: -1,
    selectedReceipts: []
};

// 通过 mutation 去更改 state 里面的值
const mutations = {
    Show_Receipt_List: (state, orderId) => {
        state.showReceiptList = true;
        state.showReceiptDialog = false;
        state.orderId = orderId;
        state.isView = false;
    },

    Set_Receipt_List: (state, data) => {
        state.receiptList = data
    },

    Show_Add_Receipt: (state) => {
        state.receipt = {
            id: -1,
            receiptNo: "",
            amount: 0.00,
            receiptDt: new Date(),
            remark: "",
            orderId: state.orderId,
        };
        state.showReceiptDialog = true;
        state.isView = false;
    },

    Set_Show_Receipt_List: (state, data) => {
        state.showReceiptList = data
    },

    Show_Edit_Receipt: (state, receipt) => {
        Object.assign(state.receipt, receipt);
        state.showReceiptDialog = true;
        state.isView = false;
    },

    Hide_Receipt_Dialog: (state) => {
        state.showReceiptDialog = false
    },

    Set_Selected_Receipt: (state, data) => {
        state.selectedReceipts = data
    },
};

// 通过 action 去 commit mutation
const actions = {

    async loadInitPageData({state}) {
        //if(!state.isInitialized){
            state.showReceiptList = false;
            let res = await Axios.get('/finance/payment/loadInitPageData', {});
            console.log("初始化查询页面：", res.result);
            state.initPageData = res.result;
            state.isInitialized = true;
        //}
    },

    showViewReceipt({state}, orderId) {
        state.showReceiptList = true;
        state.orderId = orderId;
        state.isView = true;
    },
};

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
